//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package 力扣.题库.未分类.demo1AND20;

public class demo5 {
	public demo5() {
	}

	public static void main(String[] args) {
		System.out.println(longestPalindrome("ccd"));
	}

	public static String longestPalindrome(String s) {
		if (s.isEmpty()) {
			return "";
		} else if (s.length() == 1) {
			return s;
		} else {
			int out = 0;
			int left = 0;
			int right = 0;

			for(int i = 1; i < s.length(); ++i) {
				int k = 0;

				int count;
				for(count = 0; i - 1 - k >= 0 && i + k < s.length() && s.charAt(i - 1 - k) == s.charAt(i + k); ++k) {
					count += 2;
				}

				if (count > out) {
					out = count;
					left = i - k;
					right = i + k;
				}

				count = 1;

				for(k = 0; i - 1 - k >= 0 && i + 1 + k < s.length() && s.charAt(i - 1 - k) == s.charAt(i + 1 + k); ++k) {
					count += 2;
				}

				if (count > out) {
					out = count;
					left = i - k;
					right = i + 1 + k;
				}
			}

			return s.substring(left, right);
		}
	}
}
